
import config from '@/config/config.js';
import axios from "axios";

const upkeepRequest = {
   loadAllList(searchUpkeep,pageNum,limit,callback){
       let url = config.deviceBaseUrl + "/upkeep/list?pageNum=" + pageNum + "&limit=" + limit;
       if (searchUpkeep.upkeepId){
           url += "&upkeepId=" + searchUpkeep.upkeepId;
       }
       if (searchUpkeep.upkeepName){
           url += "&upkeepName=" + searchUpkeep.upkeepName;
       }
       if (searchUpkeep.upkeepType){
           url += "&upkeepType=" + searchUpkeep.upkeepType
       }
       if (searchUpkeep.upkeepStatus){
           url += "&upkeepStatus=" + searchUpkeep.upkeepStatus
       }
       axios.get(url,{
           headers:{
               token:localStorage.getItem("token")
           }
       }).then(res=>{
           callback(res.data)
       })
   },
    loadSearchInfo(upkeepId,callback){
       let url = config.deviceBaseUrl + "/upkeep/getUpdate?upkeepId=" + upkeepId;
       axios.get(url,{
           headers:{
               token:localStorage.getItem("token")
           }
       }).then(res=>{
           callback(res.data)
       })
    },
    deleteUpkeep(upkeepId,callback){
       let url = config.deviceBaseUrl + "/upkeep/delete?upkeepId=" + upkeepId;
       axios.delete(url,{
           headers:{
               token:localStorage.getItem("token")
           }
       }).then(res=>{
           callback(res.data)
       })
    },
    insertUpkeep(insertUpkeep,callback){
       let url = config.deviceBaseUrl + "/upkeep/insert"
        axios.post(url,insertUpkeep,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    updateUpkeep(updateUpkeep,callback){
       let url = config.deviceBaseUrl + "/upkeep/update"
        axios.put(url,updateUpkeep,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    loadUpkeepDetail(upkeepId,callback){
       let url = config.deviceBaseUrl + "/upkeep/getDetail?upkeepId=" + upkeepId;
       axios.get(url,{
           headers:{
               token:localStorage.getItem("token")
           }
       }).then(res=>{
            callback(res.data)
       })
    },
    insertUPDevice(upkeepConnectInsert,callback){
        let url = config.deviceBaseUrl + "/upkeep/insertDevice";
        axios.post(url,upkeepConnectInsert,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    insertUPUPType(upkeepConnectInsert,callback){
        let url = config.deviceBaseUrl + "/upkeep/insertUpkeepType"
        axios.post(url,upkeepConnectInsert,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    deleteUPDevice(upkeepId,deviceId,callback){
        let url = config.deviceBaseUrl + "/upkeep/deleteDevice?upkeepId=" + upkeepId + "&deviceId=" + deviceId;
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    deleteUPUPType(upkeepId,upkeepTypeId,callback){
        let url = config.deviceBaseUrl + "/upkeep/deleteUpkeepType?upkeepId=" + upkeepId + "&upkeepTypeId=" + upkeepTypeId;
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    }
}
export default upkeepRequest;